Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Kafka read/write transforms without upgrading the pipeline #29362

Merged
merged 2 commits into from
Nov 17, 2023

Conversation

chamikaramj
Copy link
Contributor

This allows pipeline authors to upgrade Beam Kafka read/write transforms to a newer Beam version while keeping the rest of the pipeline in an older Beam version.

This will be useful for pipeline authors who wish to use newer releases of Kafka read/write transforms due to bug fixes, perf. improvements etc. but are unable to upgrade the full pipeline (for example, due to organizational restrictions).

Issue is #27943


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

Copy link
Contributor

github-actions bot commented Nov 9, 2023

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@chamikaramj
Copy link
Contributor Author

assign set of reviewers

Copy link
Contributor

github-actions bot commented Nov 9, 2023

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @bvolpato for label java.
R: @damccorm for label build.
R: @johnjcasey for label io.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

"EqualsIncompatibleType",
})
public static @Nullable String findUpgradeURN(
org.apache.beam.sdk.transforms.PTransform transform) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we fix this import?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

? extends TransformPayloadTranslator>
entry : registrar.getTransformPayloadTranslators().entrySet()) {
if (entry.getKey().equals(transform.getClass())) {
return entry.getValue().getUrn();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we care if there are multiple potential matches?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contract is to upgrade all transforms that match the URN (and TransformUpgrader already handles this).

@@ -0,0 +1,578 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class looks like it contains a bunch of relatively boilerplate code. Given that we would want translation and upgrades for all pre-built composites eventually, is there any way to try and avoid this boilerplate?

Copy link
Contributor Author

@chamikaramj chamikaramj Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So all we do here is building a Row object from the transform object and vice versa using utilities available in the Beam Schema library. The rest of the boilerplate here is mostly error/null checks which cannot be refactored away easily. We do have fromByteArray/toByteArray methods here to convert objects that do not have a Schema defined (for example, user specified functions) but these are pretty small and different classes can choose to do the serialization in different ways.

Do you have a specific refactoring in mind to simplify this code ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't, good to know this was thought through

Copy link
Contributor Author

@chamikaramj chamikaramj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

? extends TransformPayloadTranslator>
entry : registrar.getTransformPayloadTranslators().entrySet()) {
if (entry.getKey().equals(transform.getClass())) {
return entry.getValue().getUrn();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contract is to upgrade all transforms that match the URN (and TransformUpgrader already handles this).

"EqualsIncompatibleType",
})
public static @Nullable String findUpgradeURN(
org.apache.beam.sdk.transforms.PTransform transform) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@@ -0,0 +1,578 @@
/*
Copy link
Contributor Author

@chamikaramj chamikaramj Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So all we do here is building a Row object from the transform object and vice versa using utilities available in the Beam Schema library. The rest of the boilerplate here is mostly error/null checks which cannot be refactored away easily. We do have fromByteArray/toByteArray methods here to convert objects that do not have a Schema defined (for example, user specified functions) but these are pretty small and different classes can choose to do the serialization in different ways.

Do you have a specific refactoring in mind to simplify this code ?

@chamikaramj chamikaramj force-pushed the upgrade_kafka_transforms branch from 1069662 to 85288cf Compare November 11, 2023 00:56
Copy link

codecov bot commented Nov 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9b1040b) 38.32% compared to head (85288cf) 38.34%.
Report is 2 commits behind head on master.

❗ Current head 85288cf differs from pull request most recent head aff97ef. Consider uploading reports for the commit aff97ef to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #29362      +/-   ##
==========================================
+ Coverage   38.32%   38.34%   +0.02%     
==========================================
  Files         694      693       -1     
  Lines      102373   102227     -146     
==========================================
- Hits        39231    39200      -31     
+ Misses      61549    61436     -113     
+ Partials     1593     1591       -2     
Flag Coverage Δ
python 29.88% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chamikaramj chamikaramj force-pushed the upgrade_kafka_transforms branch from 85288cf to aff97ef Compare November 15, 2023 18:31
@chamikaramj
Copy link
Contributor Author

PTAL

@chamikaramj
Copy link
Contributor Author

Run Java PreCommit

@chamikaramj
Copy link
Contributor Author

Thanks.

@chamikaramj chamikaramj merged commit 67dbdd1 into apache:master Nov 17, 2023
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants